const path = require('path')
const PrerenderSPAPlugin = require('prerender-spa-plugin')
const Renderer = PrerenderSPAPlugin.PuppeteerRenderer
module.exports = {
  baseUrl: process.env.NODE_ENV === 'production'
    ? '/'
    : '/',
  devServer: {
    host: "0.0.0.0",
    port: 80,
    disableHostCheck: true
  },
  css: {
    loaderOptions: {
      postcss: {
        plugins: [require('postcss-px2rem')({
          remUnit: 75
        })]
      }
    }
  },
  configureWebpack: config => {
    if (process.env.NODE_ENV !== 'production') {
      return
    }
    return {
      plugins: [
        new PrerenderSPAPlugin({
          staticDir: path.join(__dirname, '../dist'),
          outputDir: path.join(__dirname, 'dist'),
          indexPath: path.join(__dirname, 'dist', 'index.html'),
          routes: [ '/GiftPage', '/HelpingFriends'],
          renderer: new Renderer({
            inject: {
              foo: 'bar'
            },
            headless: false,
            renderAfterTime: 5000
          })
        })
      ]
    }
  }
}

